﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ifelse
{
    public class ifelse1
    {
        public static void Demo()
        {
            int type = 1;
            if (type == 1) { }
            else if (type == 2) { }
            else if (type == 3) { }
            else if (type == 4) { }
        }

        public static void Demo优化()
        {
            Dictionary<int, Action> dic = new Dictionary<int, Action>();
            dic.Add(1, Func1);
            dic.Add(2, Func2);
            dic.Add(3, Func3);
            dic.Add(4, Func4);

            int type = 1;

            dic[type]();

        }

        public static void Func1() { }
        public static void Func2() { }
        public static void Func3() { }
        public static void Func4() { }

    }
}
